Internet Archive Field Parsers
Parsers to convert strings from Internet Archive API responses to their native javascript equivalents.
Each parser implements the FieldParserInterface
:
export type FieldParserRawValue = string | number | boolean;
export interface FieldParserInterface<T> {
/**
* Parse the raw value and return a value of type T or undefined if unparseable
*
* @param rawValue T | undefined
*/
parseValue(rawValue: FieldParserRawValue): T | undefined;
}
They are responsible for parsing the input and returning the appropriate value or undefined
.
Usage
Instantiate a parser or use the shared instance:
const parser = new BooleanParser()
parser.parse('true') => true
BooleanParser.shared.parse('false') => false
See tests for more usage examples.
Available Parsers:
Boolean
Byte
- a number in bytesDate
- parses the various Internet Archive date formatsDuration
- Parses hh:mm:ss.ms
and ss.ms
formats to secondsMediaType
- Internet Archive media typesNumber
PageProgression
- Internet Archive page progression (right to left, left to right)String
Testing with Web Test Runner
To run the suite of Web Test Runner tests, run
yarn run test
To run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
yarn run test:watch
Linting with ESLint, Prettier, and Types
To scan the project for linting errors, run
yarn run lint
You can lint with ESLint and Prettier individually as well
yarn run lint:eslint
yarn run lint:prettier
To automatically fix many linting errors, run
yarn run format
You can format using ESLint and Prettier individually as well
yarn run format:eslint
yarn run format:prettier
Tooling configs
For most of the tools, the configuration is in the package.json
to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.